/*
 *
 * Created on 29 de Março de 2010, 18:26
 *
 */

package intopo.game.impl.pgp;

import cern.jet.random.engine.RandomEngine;

import intopo.evogame.partnerselection.config.ParsingException;
import intopo.game.DescriptionGUI;
import intopo.game.DescriptionText;
import intopo.game.FoldStrategy;
import intopo.game.gui.AbstractGameEditorComponent;
import intopo.game.gui.AbstractStrategyEditorComponent;
import intopo.game.gui.AbstractGlobalParametersComponent;
import java.io.PrintStream;
import java.lang.reflect.Constructor;
import java.util.Map;
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author <a href="mailto:plsm@ua.pt">Pedro Lopes da Silva Mariano</a>
 *
 * @version 1.0 29 de Março de 2010
 */
final public class PublicGoodProvisionDescriptionTextGUI
	extends intopo.game.AbstractDescriptionText<PublicGoodProvisionGame, PublicGoodProvisionStrategy>
	implements
		DescriptionText<PublicGoodProvisionGame, PublicGoodProvisionStrategy>,
		DescriptionGUI<PublicGoodProvisionGame, PublicGoodProvisionStrategy>
{
	final private static PublicGoodProvisionDescriptionTextGUI instance = new PublicGoodProvisionDescriptionTextGUI ();

	/**
	 * Return a map that associates tag names to game constructors. The XML file should only have a single tag whose name is a key of the returned map.
	 */
	static private Map<String, Constructor<? extends PublicGoodProvisionGame>> gameConstructors ()
	{
		Map<String, Constructor<? extends PublicGoodProvisionGame>> result;
		Constructor<PublicGoodProvisionGame> cg;
		result = new HashMap<String, Constructor<? extends PublicGoodProvisionGame>> ();
		try {
			Class<PublicGoodProvisionGame> c = PublicGoodProvisionGame.class;
			cg = c.getConstructor (Scanner.class);
			result.put (PublicGoodProvisionGame.CONSTRUCTOR_TAG, cg);
		}
		catch (NoSuchMethodException nsme) {
			System.err.println ("Class PublicGoodProvisionGame does not have a constructor (Scanner.class)");
			System.exit (1);
		}
		return result;
	}
	/**
	 * Return a map that associates tag names to strategy constructors.
	 */
	static private Map<String, Constructor<? extends PublicGoodProvisionStrategy>> strategyConstructors ()
	{
		Constructor<PublicGoodProvisionStrategy> cp;
		Map<String, Constructor<? extends PublicGoodProvisionStrategy>> result;
		result = new HashMap<String, Constructor<? extends PublicGoodProvisionStrategy>> ();
		try {
			Class<PublicGoodProvisionStrategy> c = PublicGoodProvisionStrategy.class;
			cp = c.getConstructor (Scanner.class);
			result.put (PublicGoodProvisionStrategy.CONSTRUCTOR_TAG, cp);
		}
		catch (NoSuchMethodException nsme) {
			System.err.println ("Class PublicGoodProvisionStrategy does not have a constructor (Scanner.class)");
			System.exit (1);
			return null;
		}
		return result;
	}

	public static PublicGoodProvisionDescriptionTextGUI getInstance ()
	{
		return instance;
	}

	@Override
	public void readGlobalParameters (Scanner scanner)
		throws ParsingException
	{
		PublicGoodProvisionStrategy.Parameters.read (scanner);
	}

	@Override
	public void writeGlobalParameters (PrintStream ps)
	{
		PublicGoodProvisionStrategy.Parameters.write (ps);
	}
	@Override
	public String getBinDescription (Class<? extends PublicGoodProvisionStrategy> c, int bin)
	{
		return PublicGoodProvisionStrategy.getBinDescription (bin);
	}

	/**
	 */
	public PublicGoodProvisionDescriptionTextGUI ()
	{
		super (gameConstructors (), strategyConstructors (), new FoldPublicGoodProvisionStrategy ());
	}

	@Override
	public AbstractGameEditorComponent<PublicGoodProvisionGame, PublicGoodProvisionStrategy> getGameEditorComponent ()
	{
		return new PGPEditor ();
	}

	@Override
	public AbstractStrategyEditorComponent<PublicGoodProvisionStrategy> getStrategyEditorComponent ()
	{
		return new PublicGoodProvisionStrategyComponent ();
	}

	@Override
	public AbstractGlobalParametersComponent getGlobalParametersEditorComponent ()
	{
		return new PublicGoodProvisionGlobalParametersComponent ();
	}
}
